package com.cws4cloud.cws.mall.cms.restapi;

import com.cws4cloud.cws.common.core.util.R;
import com.cws4cloud.cws.common.security.annotation.Inner;
import com.cws4cloud.cws.mall.cms.service.AdvertisementService;
import com.cws4cloud.cws.mall.cms.service.ClasslistService;
import com.cws4cloud.cws.mall.cms.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: IndexRestApi
 * @Description: 首页相关接口
 * @Author zhlj
 * @Company:digitalchina
 * @Date 2021/6/25 15:58
 */
@RestController
@RequestMapping("/index")
@Api(value = "首页相关接口", tags = {"首页相关接口"})
@Slf4j
@Inner
public class IndexRestApi {

	@Autowired
	private ClasslistService classlistService;
	@Autowired
	private NewsService newsService;
	@Autowired
	private AdvertisementService advertisementService;

	@ApiOperation(value = "获取网站导航栏", notes = "获取网站导航栏")
	@GetMapping("/getWebNavbar")
	public R getWebNavbar(boolean lazy, Integer parentId, Integer siteId) {
		log.info("获取网站导航栏");
		return R.ok(classlistService.listClasslistTrees(lazy,parentId,null,siteId));
	}

	@ApiOperation(value = "获取首页新闻", notes = "获取首页新闻")
	@GetMapping("/getHotNews")
	public  R getHotNews(@RequestParam(value = "classlistId",required = false) Integer classlisId, Integer siteId) {
		log.info("获取首页新闻");
		return R.ok(newsService.getHotNews(classlisId, siteId));
	}

	@ApiOperation(value = "获取某个栏目的新闻", notes = "获取某个栏目的新闻")
	@GetMapping("/getNewsByClasslistId/{classlistId}")
	public  R getNewsByClasslistId(@PathVariable("classlistId") Integer classlisId, Integer siteId) {
		log.info("获取首页新闻");
		return R.ok(newsService.getNewsByClasslistId(classlisId, siteId));
	}

	@ApiOperation(value = "获取首页幻灯片", notes = "获取首页幻灯片")
	@GetMapping("/getAdvertisement")
	public R getAdvertisement(Integer siteId){
		log.info("获取首页新闻");
		return R.ok(advertisementService.getPcAdvertisement(siteId));
	}



}
